﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using Portal.Exam.Model;
using Portal.Exam.Bussiness;
using Portal.Web.Model;
using Portal.Web.Utility;
using Portal.Core;
using System.Collections.ObjectModel;
using Portal.Exam.ConvertFromWordLib;

namespace Portal.Exam.Render
{
    public class GroupQuestionTreeViewRenderBll
    {
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string RootGroupQuestionId = (string)WebEnvironments.Request(SiteId, "RId");
                if (string.IsNullOrEmpty(RootGroupQuestionId)) RootGroupQuestionId = "";

                bool CheckAllowAccess = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupQuestionPermission.StaticId, GroupQuestionPermission.funcAccess, RootGroupQuestionId, WebSessionUtility.GetCurrentLoginUser().UserId, false);

                if(!CheckAllowAccess)
                    throw new Exception(ExamUltility.AccessDenied);

                string AccountType = (string)WebEnvironments.Request(SiteId, "AccountType");
                if (string.IsNullOrEmpty(AccountType)) AccountType = "";
                
                string Html =

                #region JS
 "<script language=javascript>\r\n" +
                    "     function BackFromAddGroupQuestion()\r\n"+
                    "     {\r\n"+
                    "         document.getElementById('divFormAddGroupQuestion').innerHTML='';\r\n" +
                    "         document.getElementById('divFormAddGroupQuestion').style.display='none';\r\n" +
                    "         document.getElementById('divMainForm').style.display='block';\r\n" +
                    "     }\r\n"+
                    
                    "     function BackFromUpdateGroupQuestion()\r\n" +
                    "     {\r\n" +
                    "         document.getElementById('divFormUpdateGroupQuestion').innerHTML='';\r\n" +
                    "         document.getElementById('divFormUpdateGroupQuestion').style.display='none';\r\n" +
                    "         document.getElementById('divMainForm').style.display='block';\r\n" +
                    "     }\r\n" +

                    "     function AddTreeNode(id,title)\r\n"+
                    "     {\r\n"+
                    "           var SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "           var childNode=null;\r\n"+
                    "           if(SelectedNode!=null)\r\n"+
                    "           {\r\n"+
                    "               childNode = SelectedNode.addChild({\r\n"+
                    "                       isFolder: true\r\n"+
                    "               });\r\n"+
                    "               childNode.data.href=id;\r\n"+
                    "               childNode.setTitle(title);\r\n"+
                    "           }\r\n"+
                    "     }\r\n"+

                    "     function SaveTreeNode(id,title)\r\n" +
                    "     {\r\n"+
                    "          var SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "          SelectedNode.setTitle(title);\r\n" +
                    "     }\r\n"+


                    "     function ClientAddGroupQuestion(RId,AccountType)\r\n" +
                    "     {\r\n" +
                    "         SiteId='"+SiteId+"';\r\n"+
                    "         SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "         if(SelectedNode==null)\r\n" +
                    "         {\r\n" +
                    "            alert('Chưa xác định vào nhóm cần thêm!');\r\n" +
                    "            return;\r\n" +
                    "         }\r\n" +
                    "         ParentGroupQuestionId=document.getElementById('txtSelectedGroupQuestionId').value;\r\n" +
                    "         RootGroupQuestionId='"+RootGroupQuestionId+"';\r\n"+
                    "         AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideGetAddGroupQuestion(SiteId,RootGroupQuestionId, ParentGroupQuestionId,AccountType).value;\r\n" +
                    "         if(AjaxOut.Error)\r\n" +
                    "         {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "         }\r\n" +
                    "         document.getElementById('divFormAddGroupQuestion').innerHTML=AjaxOut.HtmlContent;\r\n"+
                    "         document.getElementById('divFormAddGroupQuestion').style.display='block';\r\n"+
                    "         document.getElementById('divMainForm').style.display='none';\r\n" +
                    "     }\r\n" +

                    "     function ClientAddQuestion(RId)\r\n" +
                    "     {\r\n" +
                    "         SiteId='"+SiteId+"';\r\n"+
                    "         ParentGroupQuestionId=document.getElementById('txtSelectedGroupQuestionId').value;\r\n" +
                    "         AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideGetAddQuestion(SiteId,RId, ParentGroupQuestionId).value;\r\n" +
                    "         if(AjaxOut.Error)\r\n" +
                    "         {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "         }\r\n" +
                    "         window.open(AjaxOut.RetUrl,'_self');\r\n"+
                    "     }\r\n" +


                    "     function ClientImport(RId)\r\n" +
                    "     {\r\n" +
                    "         SiteId='" + SiteId + "';\r\n" +
                    "         ParentGroupQuestionId=document.getElementById('txtSelectedGroupQuestionId').value;\r\n" +
                    "         RootGroupQuestionId='" + RootGroupQuestionId + "';\r\n" +
                    "         AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideGetImportGroupQuestion(SiteId,RootGroupQuestionId, ParentGroupQuestionId).value;\r\n" +
                    "         if(AjaxOut.Error)\r\n" +
                    "         {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "         }\r\n" +
                    "         document.getElementById('divFormImportGroupQuestion').innerHTML=AjaxOut.HtmlContent;\r\n" +
                    "         document.getElementById('divFormImportGroupQuestion').style.display='block';\r\n" +
                    "         document.getElementById('divMainForm').style.display='none';\r\n" +
                    "     }\r\n" +

                    "     function ClientUpdateGroupQuestion(RId)\r\n" +
                    "     {\r\n" +
                    "         SiteId='"+SiteId+"';\r\n"+
                    "         SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "         if(SelectedNode==null)\r\n"+
                    "         {\r\n"+
                    "            alert('Chưa xác định vào nhóm cần sửa!');\r\n"+
                    "            return;\r\n"+
                    "         }\r\n"+
                    "         GroupQuestionId=document.getElementById('txtSelectedGroupQuestionId').value;\r\n" +
                    "         AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideGetUpdateGroupQuestion(SiteId,GroupQuestionId).value;\r\n" +
                    "         if(AjaxOut.Error)\r\n" +
                    "         {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "         }\r\n" +
                    "         document.getElementById('divFormUpdateGroupQuestion').innerHTML=AjaxOut.HtmlContent;\r\n"+
                    "         document.getElementById('divFormUpdateGroupQuestion').style.display='block';\r\n" +
                    "         document.getElementById('divMainForm').style.display='none';\r\n" +
                    "     }\r\n" +



                    "     function ClientDeleteGroupQuestion(RId)\r\n" +
                    "     {\r\n" +
                    "         SiteId='" + SiteId + "';\r\n" +
                    "         GroupQuestionId=document.getElementById('txtSelectedGroupQuestionId').value;\r\n" +
                    "         if(GroupQuestionId=='')\r\n"+
                    "         {\r\n"+
                    "               alert('Chưa xác định nhóm cần xóa');\r\n"+
                    "               return;\r\n"+
                    "         }\r\n"+
                    "         if(GroupQuestionId==RId)\r\n" +
                    "         {\r\n" +
                    "               alert('Không xóa được nhóm gốc');\r\n" +
                    "               return;\r\n" +
                    "         }\r\n" +
                    "         if(confirm('Bạn đã chắc chắn xóa chưa?')==false)return;\r\n"+
                    "         AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideDeleteGroupQuestion(SiteId,GroupQuestionId).value;\r\n" +
                    "         if(AjaxOut.Error)\r\n" +
                    "         {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "         }\r\n" +
                    "         SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "         SelectedNode.remove();\r\n"+
                    "         tree.activateKey(RId);\r\n"+
                    "         ClientLoadQuestion(RId);\r\n"+
                    "     }\r\n" +

                    "   function DeleteQuestion(GroupQuestionId,QuestionId)\r\n" +
                    "   {\r\n" +
                    "       if(confirm('Bạn đã chắc chắn xóa câu hỏi này chưa?')==false)return;\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       Keyword=document.getElementById('txtFilterKeyword').value;\r\n"+
                    "       AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideDeleteQuestion(SiteId,GroupQuestionId,QuestionId,Keyword).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       document.getElementById('divQuestionList').innerHTML=AjaxOut.HtmlContent;\r\n" +
                    "   }\r\n" +


                    "   function UpdateQuestion(GroupQuestionId,QuestionId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideUpdateQuestion(SiteId,GroupQuestionId,QuestionId).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       window.open(AjaxOut.RetUrl,'_self');\r\n" +
                    "   }\r\n" +
                    
                    
                    "   function SearchExamQuestion()\r\n"+
                    "   {\r\n"+
                    "         SiteId='"+SiteId+"';\r\n"+
                    "         GroupQuestionId=document.getElementById('txtSelectedGroupQuestionId').value;\r\n" +
                    "         if(GroupQuestionId=='')\r\n" +
                    "         {\r\n" +
                    "               alert('Chưa xác định nhóm cần đưa câu hỏi vào');\r\n" +
                    "               return;\r\n" +
                    "         }\r\n" +
                    "       AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideGetSearchForm(SiteId,'"+RootGroupQuestionId+"',GroupQuestionId).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n"+
                    "       {\r\n"+
                    "           alert(AjaxOut.InfoMessage);\r\n"+
                    "           return;\r\n"+
                    "       }\r\n"+
                    "       document.getElementById('divSearchExamQuestion').innerHTML=AjaxOut.HtmlContent;\r\n"+
                    "       document.getElementById('divSearchExamQuestion').style.display='block';\r\n"+
                    "       document.getElementById('divMainForm').style.display='none';\r\n" +
                    "   }\r\n"+


                    "   function ClientBackFromImport()\r\n" +
                    "   {\r\n" +
                    "       document.getElementById('divFormImportGroupQuestion').innerHTML='';\r\n" +
                    "       document.getElementById('divFormImportGroupQuestion').style.display='none';\r\n" +
                    "       document.getElementById('divMainForm').style.display='block';\r\n" +
                    "   }\r\n" +






                    ///////////////// Import file

                     "function fileSelected() {\r\n" +
                        "    var file = document.getElementById('fileToUpload').files[0];\r\n" +
                        "    if (file) {\r\n" +
                        "        var fileSize = 0;\r\n" +
                        "        if (file.size > 1024 * 1024)\r\n" +
                        "            fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';\r\n" +
                        "        else\r\n" +
                        "            fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';\r\n" +
                        "        document.getElementById('fileName').innerHTML = 'Tên tệp: ' + file.name;\r\n" +
                        "        document.getElementById('fileSize').innerHTML = 'Kích cỡ: ' + fileSize;\r\n" +
                        "        document.getElementById('fileType').innerHTML = 'Loại tệp: ' + file.type;\r\n" +
                        "    }\r\n" +
                        "}\r\n" +

                        "function ClientExecuteGroupQuestionTreeViewRenderBll() {\r\n" +
                        "    if(confirm('Bạn đã chắc chắn nhập dữ liệu từ file chưa?')==false)return;\r\n" +
                        "    var fd = new FormData();\r\n" +
                        "    fd.append(\"fileToUpload\", document.getElementById('fileToUpload').files[0]);\r\n" +
                        "    var xhr = new XMLHttpRequest();\r\n" +
                        "    xhr.upload.addEventListener(\"progress\", uploadProgress, false);\r\n" +
                        "    xhr.addEventListener(\"load\", uploadComplete, false);\r\n" +
                        "    xhr.addEventListener(\"error\", uploadFailed, false);\r\n" +
                        "    xhr.addEventListener(\"abort\", uploadCanceled, false);\r\n" +
                        "    xhr.open(\"POST\", \"UploadHandler.ashx?SiteId=" + SiteId + "\");\r\n" +
                        "    xhr.send(fd);\r\n" +
                        " }\r\n" +

                        "function uploadProgress(evt) {\r\n" +
                        "    if (evt.lengthComputable) {\r\n" +
                        "    }\r\n" +
                        "    else {\r\n" +
                        "    }\r\n" +
                        "}\r\n" +

                        "function uploadComplete(evt) {\r\n" +
                        "    if(evt.target.responseText=='')\r\n" +
                        "    {\r\n" +
                        "       alert('Chưa chọn file để import!');\r\n" +
                        "       return;\r\n" +
                        "    }\r\n" +
                        "    /* This event is raised when the server send back a response */\r\n" +
                        "    document.getElementById('txtImportFile').value=evt.target.responseText;\r\n" +
                        "    //doan nay chay upload vao day...\r\n" +
                        "    ProcessImportFile()\r\n" +
                        "}\r\n" +

                        "function uploadFailed(evt) {\r\n" +
                        "    alert(\"Lỗi khi tải tệp dữ liệu lên máy chủ.\");\r\n" +
                        "}\r\n" +

                        "function uploadCanceled(evt) {\r\n" +
                        "    alert(\"Người dùng hủy bỏ tải lên máy chủ hoặc mất kết nối với máy chủ.\");\r\n" +
                        "}\r\n" +


                        "function ProcessImportFile()\r\n" +
                        "{\r\n" +
                        "    SiteId='" + SiteId + "';\r\n" +
                        "    ImportFile=document.getElementById('txtImportFile').value;\r\n" +
                        "    if(ImportFile=='')\r\n" +
                        "    {\r\n" +
                        "       alert('Chưa có file để nhập liệu!');\r\n" +
                        "       return;\r\n" +
                        "    }\r\n" +
                        
                        "    AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideReadMaxLine(SiteId, ImportFile).value;\r\n" +
                        "    if(AjaxOut.Error)\r\n" +
                        "    {\r\n" +
                        "       alert(AjaxOut.InfoMessage);\r\n" +
                        "       return;\r\n" +
                        "    }\r\n" +
                        "    MaxLine=AjaxOut.RetNumber;\r\n" +
                        "    StartLine=1;\r\n" +
                        "    document.getElementById('divImportLog').innerHTML='';\r\n" +
                        "    document.getElementById('divImportLog').style.display='block';\r\n" +
                        "    setTimeout('ImportData()',30);\r\n" +
                        "}\r\n" +

                        "function ImportData()\r\n" +
                        "{\r\n" +
                        "    if(StartLine==MaxLine)\r\n" +
                        "    {\r\n" +
                        "       StartLine=1;\r\n" +
                        "       MaxLine=0;\r\n" +
                        "       ProcessBarText = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideGetProcessBar(SiteId, MaxLine, MaxLine).value;\r\n" +
                        "       document.getElementById('divProcessing').innerHTML='';\r\n" +
                        "    }\r\n" +
                        "    else\r\n" +
                        "    {\r\n" +
                        "       ProcessBarText = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideGetProcessBar(SiteId, StartLine, MaxLine).value;\r\n" +
                        "       document.getElementById('divProcessing').innerHTML=ProcessBarText;\r\n" +
                        "       ImportFile=document.getElementById('txtImportFile').value;\r\n" +
                        "       GroupQuestionId=document.getElementById('txtSelectedGroupQuestionId').value;\r\n" +
                        "       if(GroupQuestionId=='')\r\n" +
                        "       {\r\n" +
                        "              alert('Chưa xác định nhóm cần đưa câu hỏi vào');\r\n" +
                        "              return;\r\n" +
                        "       }\r\n" +
                        "       SelectType=document.getElementById('drpSelectType').value;\r\n" +
                        "       Level=document.getElementById('drpSelectLevelGroupQuestionTreeViewRenderBll').value;\r\n" +
                        "       Overwrite=parseInt(document.getElementById('drpSelectOverwrite').value);\r\n" +
                        "       AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideProcessLine(SiteId, GroupQuestionId, SelectType, Level , ImportFile, StartLine, MaxLine, Overwrite).value;\r\n" +
                        "       ImportLog=document.getElementById('divImportLog').innerHTML;\r\n" +
                        "       if(AjaxOut.Error)\r\n" +
                        "       {\r\n" +
                        "           document.getElementById('divImportLog').innerHTML=AjaxOut.InfoMessage+'<br>'+ImportLog;\r\n" +
                        "       }\r\n" +
                        "       StartLine=StartLine+1;\r\n" +
                        "       setTimeout('ImportData()',30);\r\n" +
                        "    }\r\n" +
                        "}\r\n" +

                    "</script>\r\n" +

                #endregion

                    GroupQuestionRenderBll.GetPlugInAddGroupQuestionJavascript(SiteId,true)+
                    GroupQuestionRenderBll.GetPlugInUpdateGroupQuestionJavascript(SiteId, true) +
                    SearchExamQuestion.GetPluginJavascript(SiteId)+

                    "<div id=divFormImportGroupQuestion></div>\r\n"+
                    "<div id=divFormAddGroupQuestion></div>\r\n" +
                    "<div id=divFormUpdateGroupQuestion></div>\r\n" +
                    "<div id=divSearchExamQuestion></div>\r\n"+
                    "<div class=CssFormData id=divMainForm>\r\n" +
                        DrawFunction(SiteId, RootGroupQuestionId, AccountType).HtmlContent +
                    "<table>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=col1><div class=CssDivGroupQuestion>" +
                                DrawGroupQuestion(SiteId, RootGroupQuestionId).HtmlContent + "</div></td>\r\n" +
                    "       <td class=col2>\r\n"+
                    "           <h3>Danh sách câu hỏi trong nhóm <div style=\"float:right\">Từ khóa: <input id=txtFilterKeyword style=\"margin-right:5px;\"><input type=button class=button value=\"Lọc dữ liệu\" onclick=\"javascript:ClientRefresh(0);\"></div></h3>\r\n" +
                    "           <div class=CssQuestionList id=\"divQuestionList\">" +
                                       ServerSideReadingQuestionInGroupQuestion(SiteId, RootGroupQuestionId, "",0).HtmlContent + "\r\n" +
                    "           </div>\r\n"+
                    "       </td>\r\n" +
                    "   </tr>\r\n" +
                    "</table>\r\n" +
                    "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawGroupQuestion(
            string SiteId,
            string RootGroupQuestionId
            )
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                GroupQuestionCls OGroupQuestion = GroupQuestionBll.CreateGroupQuestionModel(SiteId, RootGroupQuestionId);
                string Html =
                              "<script language=javascript>\r\n" +
                              "     function ClientLoadQuestion(GroupQuestionId)\r\n" +
                              "     {\r\n" +
                              "         SiteId='" + SiteId + "';\r\n" +
                              "         document.getElementById('txtSelectedGroupQuestionId').value = GroupQuestionId;\r\n" +
                              "         Keyword=document.getElementById('txtFilterKeyword').value;\r\n" +
                              "         CurrentPageIndex=parseInt(document.getElementById('txtCurrentPageIndex').value);\r\n" +
                              "         AjaxOut = Portal.Exam.Render.GroupQuestionTreeViewRenderBll.ServerSideReadingQuestionInGroupQuestion(SiteId,GroupQuestionId,Keyword, CurrentPageIndex).value;\r\n" +
                              "         document.getElementById('divQuestionList').innerHTML=AjaxOut.HtmlContent;\r\n" +
                              "     }\r\n" +

                              "     function ClientRefresh(CurrentPageIndex)\r\n" +
                              "     {\r\n" +
                              "         SiteId='" + SiteId + "';\r\n" +
                              "         GroupQuestionId=document.getElementById('txtSelectedGroupQuestionId').value;\r\n" +
                              "         document.getElementById('txtCurrentPageIndex').value=CurrentPageIndex;\r\n" +
                              "         ClientLoadQuestion(GroupQuestionId);\r\n" +
                              "     }\r\n" +
                              "</script>\r\n" +
                              "<input type=hidden id=\"txtCurrentPageIndex\" value=\"0\">\r\n" +
                              "<input type=hidden id=\"txtSelectedGroupQuestionId\" value=\"" + RootGroupQuestionId + "\">\r\n" +
                              "<h3><a href=\"GroupQuestionTreeView.aspx?RId=" + RootGroupQuestionId + "\">" + OGroupQuestion.GroupQuestionName + "</a></h3>\r\n" +
                              "<div class=TreeHolder>\r\n" +
                              "<div id=\"tree\">\r\n" +
                              "<ul>\r\n" +
                              " <li class=\"folder expanded\"><a href=\"" + RootGroupQuestionId + "\" target=\"_self\">" + OGroupQuestion.GroupQuestionName + "</a>\r\n" +
                              "     <ul>\r\n";
                GroupQuestionCls[] GroupQuestions = GroupQuestionBll.ReadingGroupQuestion(SiteId, RootGroupQuestionId);
                for (int iIndex = 0; iIndex < GroupQuestions.Length; iIndex++)
                {
                    Html +=
                            "<li class=\"folder expanded\"><a href=\"" + GroupQuestions[iIndex].GroupQuestionId + "\" target=\"_self\">" + GroupQuestions[iIndex].GroupQuestionName + "</a>\r\n" +
                                BuildSubTreeView(SiteId, GroupQuestions[iIndex].GroupQuestionId).HtmlContent +
                            "</li>\r\n";
                }

                Html += "</ul>\r\n" +
                        "</li>\r\n" +
                        "</ul>\r\n" +
                        "</div>\r\n" +
                        "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut BuildSubTreeView(string SiteId, string ParentGroupQuestionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string Html = "";
                GroupQuestionCls[] GroupQuestions = GroupQuestionBll.ReadingGroupQuestion(SiteId, ParentGroupQuestionId);
                Html +=
                    "<ul>\r\n";
                for (int iIndex = 0; iIndex < GroupQuestions.Length; iIndex++)
                {
                    Html +=
                            "<li class=\"folder expanded\"><a target=\"_self\" href=\"" + GroupQuestions[iIndex].GroupQuestionId + "\">" + GroupQuestions[iIndex].GroupQuestionName + "</a>\r\n" +
                                BuildSubTreeView(SiteId, GroupQuestions[iIndex].GroupQuestionId).HtmlContent +
                            "</li>\r\n";
                }

                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawFunction(
            string SiteId, 
            string RootGroupQuestionId,
            string AccountType
            )
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                bool CheckAllowManage = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupQuestionPermission.StaticId, GroupQuestionPermission.funcManage, RootGroupQuestionId, WebSessionUtility.GetCurrentLoginUser().UserId, false);
                string Html =
                   "<div class=FormFunction id=divListForm>\r\n" +
                   " <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n";
                if (CheckAllowManage)
                {
                    Html +=
                       "            <li onclick=\"javascript:ClientAddGroupQuestion('" + RootGroupQuestionId + "','" + AccountType + "');\"><img class=image src=\"" + IconRoot + "/Add.png\"><div>Tạo nhóm</div></li>\r\n" +
                       "            <li onclick=\"javascript:ClientDeleteGroupQuestion('" + RootGroupQuestionId + "');\"><img class=image src=\"" + IconRoot + "/Delete.png\"><div>Xóa nhóm</div></li>\r\n" +
                       "            <li onclick=\"javascript:ClientUpdateGroupQuestion('" + RootGroupQuestionId + "');\"><img class=image src=\"" + IconRoot + "/Update.png\"><div>Sửa nhóm</div></li>\r\n" +
                       "            <li onclick=\"javascript:ClientAddQuestion('" + RootGroupQuestionId + "');\"><img class=image src=\"" + IconRoot + "/Add.png\"><div>Tạo mới câu hỏi</div></li>\r\n";
                       }
                bool CheckAllowImport = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupQuestionPermission.StaticId, GroupQuestionPermission.funcImport, RootGroupQuestionId, WebSessionUtility.GetCurrentLoginUser().UserId, false);
                if (CheckAllowImport)
                {
                    Html +=
                       "            <li onclick=\"javascript:ClientImport();\"><img class=image src=\"" + IconRoot + "/Import.png\"><div>Nhập câu hỏi</div></li>\r\n";
                }
                Html +=
                   "            <li onclick=\"javascript:ClientMoveGroupQuestion();\"><img class=image src=\"" + IconRoot + "/Move.png\"><div>Chuyển</div></li>\r\n" +
                   "            <li onclick=\"javascript:ClientRefresh(0);\"><img class=image src=\"" + IconRoot + "/Refresh.png\"><div>Đọc lại danh sách</div></li>\r\n" +
                   "            <li onclick=\"javascript:window.open('GroupQuestion.aspx','_self');\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideReadingQuestionInGroupQuestion(
            string SiteId, 
            string GroupQuestionId,
            string Keyword,
            int    CurrentPageIndex)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string Html = "";
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);

                bool CheckAllowManage = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, ExamPermission.StaticId, ExamPermission.funcQuestionManage, ExamPermission.StaticId, WebSessionUtility.GetCurrentLoginUser().UserId, false);

                GroupQuestionCls OGroupQuestion = null;
                if (!string.IsNullOrEmpty(GroupQuestionId))
                {
                    OGroupQuestion = GroupQuestionBll.CreateGroupQuestionModel(SiteId, GroupQuestionId);
                }
                
                if (OGroupQuestion != null)
                {
                    Html +=
                        "<h3>Đang chọn nhóm: " + OGroupQuestion.GroupQuestionName + "</h3>";
                }
                DataTable dtQuestion = GroupQuestionBll.ReadingQuestionForGroupQuestion(SiteId, GroupQuestionId, Keyword);
                if (dtQuestion.Rows.Count == 0)
                {
                    Html += "<div class=CssNoData>Không có câu hỏi nào thuộc nhóm câu hỏi này</div>\r\n";
                }
                else
                {
                    ReturnPaging OReturnPaging = WebPaging.GetPaging(dtQuestion.Rows.Count, CurrentPageIndex, 25, 10, "ClientRefresh");
                    Html += 
                        OReturnPaging.PagingText+
                           "<div class=tabcontent id=divListQuestionResult>\r\n" +
                           "    <table>\r\n" +
                           "        <tr>\r\n" +
                           "            <th class=thIndex>#</th>\r\n" +
                           "            <th>Câu hỏi</th>\r\n" +
                           "            <th>Kiểu</th>\r\n" +
                           "            <th></th>\r\n" +
                           "            <th></th>\r\n" +
                           "            <th></th>\r\n" +
                           //"            <th></th>\r\n" +
                           "        </tr>\r\n";
                    for (int iIndex = OReturnPaging.StartIndex; iIndex < OReturnPaging.EndIndex; iIndex++)
                    {
                        string QuestionId = (string)dtQuestion.Rows[iIndex]["QuestionId"];
                        string Type = (string)dtQuestion.Rows[iIndex]["Type"];
                        string Title = (string)dtQuestion.Rows[iIndex]["Title"];
                        Html +=
                           "        <tr>\r\n" +
                           "            <td class=tdIndex>" + (iIndex + 1) + "</td>\r\n" +
                           "            <td><span class=CssQuestionSubject><a href=\"#\">" + Title + "</a></span></td>\r\n" +
                           "            <td>" + Type + "</td>\r\n";
                        if (CheckAllowManage)
                        {
                            Html +=
                           "            <td class=tdButton><a href=\"javascript:DeleteQuestion('" + GroupQuestionId + "','" + QuestionId + "');\"><img alt=\"Xóa câu hỏi\" title=\"Xóa câu hỏi\" class=imagebutton src=\"" + IconRoot + "/delete.png\"></a></td>\r\n" +
                           "            <td class=tdButton><a href=\"javascript:UpdateQuestion('" + GroupQuestionId + "','" + QuestionId + "');\"><img alt=\"Sửa câu hỏi\" title=\"Sửa\" class=imagebutton src=\"" + IconRoot + "/Update.png\"></a></td>\r\n";
                        } Html +=
                           "            <td class=tdButton><a href=\"javascript:ViewQuestion('" + GroupQuestionId + "','" + QuestionId + "');\"><img alt=\"Xem câu hỏi\" title=\"Xem câu hỏi\" class=imagebutton src=\""+IconRoot+"/preview.png\"></a></td>\r\n" +                           
                           "        </tr>\r\n";
                    }
                    Html += "</table>\r\n" +
                            "</div>\r\n";
                }
                OAjaxOut.HtmlContent = Html;
                    
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }





        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetAddGroupQuestion(
            string SiteId,
            string RootGroupQuestionId,
            string ParentGroupQuestionId,
            string AccountType)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut =
                    GroupQuestionRenderBll.DrawAddGroupQuestionForAjax(SiteId, RootGroupQuestionId, ParentGroupQuestionId,AccountType,"javascript:History(-1);");
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetAddQuestion(
            string SiteId,
            string RootGroupQuestionId,
            string ParentGroupQuestionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut.RetUrl = "AddQuestion.aspx?RootGroupQuestionId=" + RootGroupQuestionId+"&GroupQuestionId="+ParentGroupQuestionId;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetImportGroupQuestion(
            string SiteId,
            string RootGroupQuestionId,
            string ParentGroupQuestionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                GroupQuestionCls ORootGroupQuestion = GroupQuestionBll.CreateGroupQuestionModel(SiteId, RootGroupQuestionId);
                GroupQuestionCls OSubGroupQuestion = GroupQuestionBll.CreateGroupQuestionModel(SiteId, ParentGroupQuestionId);
                string DisplayText = ORootGroupQuestion.GroupQuestionName;
                if (OSubGroupQuestion != null)
                {
                    if (!OSubGroupQuestion.GroupQuestionId.Equals(ORootGroupQuestion.GroupQuestionId))
                    {
                        DisplayText += " / " + OSubGroupQuestion.GroupQuestionName;
                    }
                }

                string[] Types = new string[]{
                    "BestAnswer","YesNo"//,"MultiChoice"
                };
                string[] SubjectTypes = new string[]{
                    "Câu hỏi 1 phương án đúng nhất","Câu hỏi dạng đúng hoặc sai"//,"Các đáp án đúng"
                };

                string SelectTypeText = "<select class=drplist id=drpSelectType onchange=javascript:JumPageGroupQuestionTreeViewRenderBll(0);>";
                for (int iIndex = 0; iIndex < Types.Length; iIndex++)
                {
                    SelectTypeText += "<option value=\"" + Types[iIndex] + "\">" + SubjectTypes[iIndex] + " (" + Types[iIndex] + ")</option>";
                }
                SelectTypeText += "</select>";


                string SelectLevelText =
                    "<select id=drpSelectLevelGroupQuestionTreeViewRenderBll class=drplist>\r\n" +
                    "   <option value=\"0\">Mức độ dễ</option>\r\n" +
                    "   <option value=\"1\">Mức độ trung bình</option>\r\n" +
                    "   <option value=\"2\">Mức độ khó</option>\r\n" +
                    "</select>\r\n";


                string SelectOverwriteText =
                    "<select id=drpSelectOverwrite class=drplist>\r\n" +
                    "   <option value=\"0\">Không đè nếu tồn tại</option>\r\n" +
                    "   <option value=\"1\">Ghi đè nếu tồn tại</option>\r\n" +
                    "</select>\r\n";

                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string RetHtml =
                    " <div class=DatabaseFunction>\r\n" +
                    "        <ul>\r\n" +
                    "            <li onclick=\"javascript:ClientExecuteGroupQuestionTreeViewRenderBll();\"><img class=image src=\"" + IconRoot + "/Execute.png\"><div>Nhập câu hỏi</div></li>\r\n" +
                    "            <li onclick=\"javascript:ClientBackFromImport();\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                    "        </ul>\r\n" +
                    " </div>\r\n"+
                    " <div class=CssFormSaveUpdate>\r\n" +
                    "   <table>" +
                    "       <tr>" +
                    "           <td class=Col1>Thuộc thư mục:</td>" +
                    "           <td class=Col2>" + DisplayText + "</td>" +
                    "       </tr>" +
                    "       <tr>" +
                    "           <td class=Col1>Kiểu câu hỏi:</td>" +
                    "           <td class=Col2>" + SelectTypeText + "</td>" +
                    "       </tr>" +
                    "       <tr>" +
                    "           <td class=Col1>Mức độ:</td>" +
                    "           <td class=Col2>" + SelectLevelText + "</td>" +
                    "       </tr>" +
                    "       <tr>" +
                    "           <td class=Col1>Tham số:</td>" +
                    "           <td class=Col2>" + SelectOverwriteText + "</td>" +
                    "       </tr>" +
                    "       <tr>\r\n"+
                    "           <td class=Col1>Chọn tệp:</td>\r\n"+
                    "           <td class=Col2>\r\n"+
                    "                   <input type=\"file\" name=\"fileToUpload[]\" id=\"fileToUpload\" onchange=\"fileSelected();\" /><div style=\"margin-top:10px;\"></div>\r\n" +//<input type=button class=button onclick=\"uploadFile()\" value=\"Thực hiện nhập dữ liệu từ tệp\" /><input type=button class=button onclick=\"SaveLog()\" value=\"Ghi Log import\" />
                    "                   <div id=divLinkSaveLog></div>\r\n" +
                    "                   <div id=\"fileName\"></div>\r\n" +
                    "                   <div id=\"fileSize\"></div>\r\n" +
                    "                   <div id=\"fileType\"></div>\r\n" +
                    "                   <div id=divProcessing></div>\r\n" +
                    "                   <div id=\"divImportLog\" style=\"padding:4px;border:solid 1px silver;height:200px;overflow:auto;display:none;\"></div>\r\n" +
                    "                   <input type=hidden id=txtImportFile value=\"\">\r\n" +
                    "                   <div class=CssTip style=\"color:maroon;font-size:12px;\"><i>(*) Chú ý: File phải đúng định dạng quy định theo <a href=\"ExcelTemplate/ExamStudentList.xls\">biểu mẫu</a> sau đó save as thành file text với định dạng unicode và dùng file này để import</i></div>\r\n" +
                    "           </td>\r\n"+
                    "       </tr>\r\n"+
                    "   </table>" +
                    " </div>\r\n" +
                    " <div id=divProcessingImport></div>";
                OAjaxOut.HtmlContent = RetHtml;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetUpdateGroupQuestion(
            string SiteId,
            string GroupQuestionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut =
                    GroupQuestionRenderBll.DrawUpdateGroupQuestionForAjax(SiteId, GroupQuestionId, "javascript:BackFromUpdateGroupQuestion();");
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }
        
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDeleteGroupQuestion(
            string SiteId,
            string GroupQuestionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                GroupQuestionBll.DeleteGroupQuestion(SiteId, GroupQuestionId);
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetSearchForm(
            string SiteId,
            string RootGroupQuestionId,
            string GroupQuestionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut.HtmlContent = SearchExamQuestion.Draw(SiteId, GroupQuestionId).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDeleteQuestion(
            string SiteId,
            string GroupQuestionId,
            string QuestionId,
            string Keyword)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                new QuestionBll().DeleteQuestion(null, SiteId, QuestionId);
                OAjaxOut.HtmlContent = ServerSideReadingQuestionInGroupQuestion(SiteId, GroupQuestionId, Keyword, 0).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideUpdateQuestion(
            string SiteId,
            string GroupQuestionId,
            string QuestionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string UpdateUrl = "UpdateQuestion.aspx?QuestionId=" + QuestionId + "&RootGroupQuestionId=" + GroupQuestionId;
                OAjaxOut.RetUrl = UpdateUrl;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }



        //import file
        [AjaxPro.AjaxMethod]
        public static AjaxOut ServerSideReadMaxLine(string SiteId, string ImportFile)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                //doan nay tao ra file xml
                int Max = WordToXmlConverter.GetMax(ImportFile);
                //DataSet ds = new DataSet();
                //ds.ReadXml(ImportFile);
                OAjaxOut.RetNumber = Max;
                //ds.Tables["Question"].Rows.Count;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod]
        public static string ServerSideGetProcessBar(string SiteId, int ProcessLine, int MaxLine)
        {
            int MaxW = 700;
            decimal W = 0;
            decimal Percent = 0;
            if (MaxLine > 0)
            {
                W = (decimal)MaxW * (decimal)ProcessLine / (decimal)MaxLine;
                Percent = ((decimal)ProcessLine / (decimal)MaxLine) * 100;
            }
            if (Percent < 1) Percent = 1;
            if (Percent > 100) Percent = 100;
            string HtmlProgressBar = "<div style=\"width:" + MaxW + "px;padding:10px; background-color:silver;border:solid 1px black;height:55px;margin-top:10px;margin-bottom:10px;\">\r\n" +
                                     "   <div style=\"padding:4px;\">Xử lý dòng " + (ProcessLine + 1) + "/" + MaxLine + "</div>\r\n" +
                                     "   <div style='border:solid 1px black;padding:4px;background-color:blue;color:white;width:" + W.ToString("###0") + "px'>" + Percent.ToString("#,##0") + "% </div>\r\n" +
                                     "</div>\r\n";

            return HtmlProgressBar;
        }


        [AjaxPro.AjaxMethod]
        public static AjaxOut ServerSideProcessLine(
            string SiteId,
            string GroupQuestionId,
            string QuestionType,
            string LevelImport,
            string ImportFile,
            int    ProcessLine,
            int    MaxLine,
            int    Overwrite)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            OAjaxOut.InfoMessage = "";
            QuestionCls OQuestion = new QuestionCls();
            try
            {
                //DataSet ds = new DataSet();
                //ds.ReadXml(ImportFile);
                //DataTable dtQuestion = ds.Tables["Question"];
                WebSessionUtility.CheckSessionTimeOut();
                int QuestionIndex = ProcessLine - 1;
                
                if (QuestionIndex == MaxLine)
                {
                    return OAjaxOut;
                }

                WordQuestionCls OWordQuestion = WordToXmlConverter.GetOneQuestion(ImportFile, QuestionIndex);
                if (OWordQuestion == null)
                {
                    return OAjaxOut;
                }
                string AssetCode = WebSessionUtility.GetCurrentLoginUser().AssetCode;

                OQuestion.QuestionId = OWordQuestion.QuestionId;
                OQuestion.Title = OWordQuestion.Subject;
                OQuestion.Type = QuestionType;
                OQuestion.Level = int.Parse(LevelImport);
                OQuestion.Answers = new System.Collections.ObjectModel.Collection<AnswerCls> { };
                for (int iIndexAnswer = 0; iIndexAnswer < OWordQuestion.AnswerItems.Count; iIndexAnswer++)
                {
                    AnswerCls OAnswer = new AnswerCls();
                    OAnswer.AnswerId = OWordQuestion.AnswerItems[iIndexAnswer].AnswerId;
                    OAnswer.AnswerTextFirst = OWordQuestion.AnswerItems[iIndexAnswer].AnswerText;
                    bool Correct = OWordQuestion.AnswerItems[iIndexAnswer].IsAnswer;
                    if (Correct)
                    {
                        OQuestion.CorrectOrder = iIndexAnswer;// ?1:0;
                    }
                    OAnswer.CorrectOrder = Correct ? 1 : 0;
                    OAnswer.IndexOrder = iIndexAnswer + 1;
                    if (string.IsNullOrEmpty(OAnswer.AnswerTextFirst) && string.IsNullOrEmpty(OAnswer.AnswerTextLast))
                    {
                        //trang khong lam gi ca
                    }
                    else
                    {
                        OQuestion.Answers.Add(OAnswer);
                    }
                }
                new QuestionBll().AddQuestion(null, SiteId, GroupQuestionId, QuestionType, int.Parse(LevelImport), OQuestion, Overwrite);
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                string ErrorMsg = ex.Message.ToString();
                if (ErrorMsg.IndexOf("Violation of PRIMARY KEY") != -1)
                {
                    ErrorMsg = "Đã có câu hỏi '" + OQuestion.Title + "' trong cơ sở dữ liệu";
                }
                OAjaxOut.InfoMessage = "Lỗi xử lý dòng " + (ProcessLine + 1) + " => " + ErrorMsg;
            }
            return OAjaxOut;
        }
    }
}
